using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Configuration;
using System.Windows.Forms;
namespace XProject
{
    class DBAccess
    {
       
       protected string strConn;
       protected OleDbConnection conn;
        string message;
        public string Message { get { return message; } }
        public DBAccess()
        {           
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\db\\db1.mdb;Jet OLEDB:Database Password=" + ConfigurationManager.AppSettings["db_pass"];
            conn = new OleDbConnection(strConn);
        }
        public bool Connect()
        {
            try
            {
                if (conn.State != System.Data.ConnectionState.Open)
                    conn.Open();
                else if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                    conn.Open();
                }
                return true;
            }
            catch (OleDbException ex)
            {
                this.message ="Database connection error: "+ ex.Message;
                return false;
            }
            catch (Exception ex) { this.message = ex.Message; }
            return false;
        }
        public void Disconnect()
        {
            conn.Close();
        }
    }
}
